package com.example.myapplication;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.card.MaterialCardView;

import java.util.List;

public class CourseDetailActivity extends AppCompatActivity {
    private ImageView imageViewCourse;
    private TextView textViewName, textViewTime, textViewLocation, textViewDescription;
    private MaterialCardView cardView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course_detail);

        // 获取传递的数据
        int courseId = getIntent().getIntExtra("courseId", -1);
        String courseName = getIntent().getStringExtra("courseName");
        String courseTime = getIntent().getStringExtra("courseTime");
        String courseLocation = getIntent().getStringExtra("courseLocation");

        // 绑定视图
        imageViewCourse = findViewById(R.id.imageViewCourse);
        textViewName = findViewById(R.id.textViewName);
        textViewTime = findViewById(R.id.textViewTime);
        textViewLocation = findViewById(R.id.textViewLocation);
        textViewDescription = findViewById(R.id.textViewDescription);


        textViewName.setText(courseName);
        textViewTime.setText("时间: " + courseTime);
        textViewLocation.setText("地点: " + courseLocation);
        List<Course> sampleCourses = CourseDataGenerator.generateSampleCourses();
        // 根据name找到对应的cousrse
        Course course = null;
        for (Course c : sampleCourses) {
            if (c.getName().equals(courseName)) {
                course = c;
                break;
            }
        }
        if (course == null) {
            textViewDescription.setText("简介: " +"暂无简介");
            return;
        }
        textViewDescription.setText("简介: " + course.getDescription());
    }
}
